package com.wavefront.obj.parser.line;

import com.wavefront.obj.elements.VertexUV;
import com.wavefront.obj.parser.LineParser;
import com.wavefront.obj.parser.ObjParser;

public class TextureCooParser extends LineParser {

	private VertexUV uv = null;

	public TextureCooParser() {
	}

	@Override
	public void parse(String[] words) {
		super.parse(words);
		uv = ObjParser.currentModel.createVertexUV();
		try {
			if (words.length >= 2)
				uv.setU(Float.parseFloat(words[1]));

			if (words.length >= 3)
				uv.setV(1 - Float.parseFloat(words[2])); // OBJ origin
															// is at
															// upper
															// left,
															// OpenGL
															// origin is
															// at lower
															// left.

			if (words.length >= 4)
				uv.setW(Float.parseFloat(words[3]));

		} catch (Exception e) {
			throw new RuntimeException("TextureParser Error");
		}
	}

}
